package com.d3works.apps.hr.service.batch;

import com.d3works.apps.base.db.Batch;
import com.d3works.apps.base.db.MailBatch;
import com.d3works.apps.base.db.repo.MailBatchRepository;
import com.d3works.apps.base.service.batch.MailBatchService;
import com.d3works.apps.hr.service.app.AppHumanResourceService;
import com.d3works.db.Model;
import com.d3works.exception.D3worksException;
import com.d3works.inject.Beans;

public class MailBatchServiceHR extends MailBatchService {

  @Override
  public Batch run(Model batchModel) throws D3worksException {

    if (!Beans.get(AppHumanResourceService.class).isApp("employee")) {
      return super.run(batchModel);
    }

    MailBatch mailBatch = (MailBatch) batchModel;

    switch (mailBatch.getActionSelect()) {
      case MailBatchRepository.ACTION_TIMESHEET_VALIDATION_REMINDER:
        return runTimesheetValidationReminderBatch(mailBatch);

      default:
        return super.run(batchModel);
    }
  }

  public Batch runTimesheetValidationReminderBatch(MailBatch mailBatch) {
    return Beans.get(BatchTimesheetValidationReminder.class).run(mailBatch);
  }
}
